package com.tnovoselec.android.mojevijesti.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.actionbarsherlock.app.SherlockFragment;
import com.tnovoselec.android.mojevijesti.R;
import com.tnovoselec.android.mojevijesti.activity.NewsDetailsActivity;
import com.tnovoselec.android.mojevijesti.adapter.NewsAdapter;
import com.tnovoselec.android.mojevijesti.dto.NewsResultHolder;

public class NewsFragment extends SherlockFragment implements OnItemClickListener{

	private ListView list;
	private NewsAdapter adapter;
	private int key;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		Bundle args = getArguments();
		key = args.getInt("key");
		//Log.i("Key", key);
		View v = inflater.inflate(R.layout.newslist, container, false);
		list = (ListView) v.findViewById(R.id.news_list);
		adapter = new NewsAdapter(getActivity(), NewsResultHolder.get(key));
		list.setAdapter(adapter);
		list.setOnItemClickListener(this);
		return v;
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		Intent i = new Intent(getActivity(), NewsDetailsActivity.class);
		i.putExtra("channel", key);
		i.putExtra("position", arg2);
		startActivity(i);
		
	}
	


}
